<template>
      <div style="width: 100%">
<!--            <div style="margin-top: 5px;text-align: center">-->
<!--                  <el-input v-model="name" placeholder="请输入姓名" style="width: 100px" suffix-icon="Search"-->
<!--                            @keyup.enter.native="loadGet"-->
<!--                  ></el-input>-->
<!--                  <el-button style="margin-left: 5px" type="primary" @click="loadGet">查询</el-button>-->

<!--            </div>-->
            <el-scrollbar>
                  <el-table :data="tableData">
                        <el-table-column label="申请人" prop="persona"/>
                        <el-table-column label="被申请人" prop="personb"/>
                       <el-table-column label="申请时间" prop="time2"/>
                        <el-table-column label="状态" prop="flag">
                              <template v-slot="scope">
                                    <el-tag
                                              :type="scope.row.flag=== 0 ? 'danger' :'primary' "
                                              disable-transitions
                                    >{{ scope.row.flag === 0 ? '未结案' : '已结案' }}
                                    </el-tag
                                    >
                              </template>
                        </el-table-column>
                        <el-table-column label="操作" prop="operate">
                              <template v-slot="scope">
                                    <el-button size="small" type="success" @click="assistanceDetail(scope.row.content)">案由详情</el-button>
                                    <el-popconfirm  title="Delete this?"  @confirm="del(scope.row.id)">
                                          <template #reference>
                                                <el-button   size="small" type="danger">删除记录</el-button>
                                          </template>
                                    </el-popconfirm>
                              </template>
                        </el-table-column>
                  </el-table>
            </el-scrollbar>

            <el-dialog
                      v-model="dialogVisible"
                      title="案由详情"
                      width="440px"
                      style="text-align: center"
            >
                  <el-form :model="form" label-width="auto" style="max-width: 600px;height: 330px"  :rules="rules" ref="form">
                        <el-form-item label="" prop="content">
                              <el-col :span="22">
                                    <el-input v-model="form.content"  type="textarea"/>
                              </el-col>
                        </el-form-item>
                  </el-form>

            </el-dialog>
      </div>
</template>

<script>
export default {
      name: "aidWork",
      data(){
            return{
                  tableData:[],
                  form: {
                        id:'',
                        persona:'',
                        personb: '',
                        lawyer:'',
                        time1:'',
                        time2:'',
                        time3:'',
                        flag:'',
                        content:''
                  },
                  lawyerForm: {
                        id: '',
                        name: '',
                        password: '',
                        card: '',
                        classify: '',
                        credential: '',
                        state: '',
                        num: '',
                        crenum: '',
                        img: ''
                  },
                  dialogVisible:false,
            }
      },
      methods:{
            init(){
                  this.lawyerForm = JSON.parse(sessionStorage.getItem('CurUser'))
                  console.log("lawyerName="+this.lawyerForm.name)
            },
            loadGet() {
                  this.$axios.get('http://localhost:8088/assistance/findByLawyer?lawyer='+this.lawyerForm.name, {
                  }).then(res => res.data).then(res => {
                        console.log(res)
                        if (res.code === 200) {
                              // alert("是200")
                              this.tableData = res.data
                              console.log("assistance==="+res.data)
                        } else {
                              alert("不是200")
                        }
                  })
            },
            assistanceDetail(row){
                  console.log(row)
                  //      赋值到表单
                  this.dialogVisible=true
                  this.$nextTick(()=>{
                        this.form.content=row
                  })


            },
            del(id){
                  console.log(id)
                  this.$axios.get('http://localhost:8088/assistance/del?id='+id).then(res => res.data).then(res => {
                        console.log(res)
                        if (res.code === 200) {
                              this.$message({
                                    message: 'Congrats, this is a success message.',
                                    type: 'success',
                              })
                              this.loadGet()
                        } else {
                              this.$message({
                                    message: 'Regret, this is a error message.',
                                    type: 'danger',
                              })

                        }
                  })
            },
      },
      mounted() {
            this.init()
            this.loadGet()
      }
}
</script>

<style scoped>
.el-textarea {
      height: 88px;
}

:deep(.el-textarea__inner) {
      height: 300px;
      width: 400px;
}

</style>